package com.yonyou.gmmc.service.information.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.marketing.common.constants.ResultMsgConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.yonyou.gmmc.common.annotation.ParamValid;
import org.marketing.common.Response;
import com.yonyou.gmmc.service.information.constant.InformationConstant;
import com.yonyou.gmmc.service.information.model.TmCarKnowledges;
import com.yonyou.gmmc.service.information.model.TmExamineCarResult;
import com.yonyou.gmmc.service.information.service.CarKnowledgesService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
*
* @author Administrator
* TODO description
* @date 2017年3月10日
*/

@RestController
@RequestMapping(value = InformationConstant.BASE_PATH + "/" + InformationConstant.VERSION)
@Api("用车知识")
public class CarKnowledgesController {
	private Logger logger = Logger.getLogger(CarKnowledgesController.class);
	@Autowired
	private CarKnowledgesService carKnowledgesService;
	/**
	 * 用车知识查询
	 * 
	 * @author Administrator TODO description
	 * @date 2017年4月17日
	 * @return
	 */
	@RequestMapping(value = "/findCarKnow", method = RequestMethod.GET)
	@ApiOperation(value = "用车知识查询", notes = "用车知识查询")
	@ParamValid
	public Response<PageInfo<TmCarKnowledges>> findCarKnow(@RequestParam(required=false,defaultValue="0") Integer pageNum
    		,@RequestParam(required=false,defaultValue="10") Integer pageSize
    		,@RequestParam(required=false,defaultValue="") String title) {
		logger.info("CarKnowledgesController.findCarKnow==>start...");
		try {
			Map<String,Object> map = new HashMap<>();
			map.put("pageNum", pageNum);
			map.put("pageSize", pageSize);
			map.put("title", title);
			PageInfo<TmCarKnowledges> result = carKnowledgesService.findCarKnow(map);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("CarKnowledgesController.findCarKnow==>end...");
		}
	}
	/**
	 * 用车知识查询
	 * 
	 * @author Administrator TODO description
	 * @date 2017年4月17日
	 * @return
	 */
	@RequestMapping(value = "/findCarKnowDetail", method = RequestMethod.GET)
	@ApiOperation(value = "用车知识详情", notes = "用车知识详情")
	@ParamValid
	public Response<List<TmCarKnowledges>> findCarKnowDetail(@RequestParam(required=true,defaultValue="0") Integer carId) {
		logger.info("CarKnowledgesController.findCarKnowDetail==>start...");
		try {
			List<TmCarKnowledges> result = carKnowledgesService.findCarKnowDetail(carId);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("CarKnowledgesController.findCarKnowDetail==>end...");
		}
	}
	
	/**
	 * 获取车系（爱车检查）
	 * @return
	 */
	@RequestMapping(value = "/acquireSeries", method = RequestMethod.GET)
	@ApiOperation(value = "获取车系（爱车检查）", notes = "获取车系（爱车检查）")
	public Response<List<Map<String,Object>>> acquireSeries() {
		logger.info("获取车系（爱车检查）==>start...");
		try {
			List<Map<String, Object>> result = carKnowledgesService.acquireSeries();
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("获取车系（爱车检查）==>end...");
		}
	}
	
	
	/**
	 * 获取车型（爱车检查）
	 * @return
	 */
	@RequestMapping(value = "/acquireModel", method = RequestMethod.GET)
	@ApiOperation(value = "获取车型（爱车检查）", notes = "获取车型（爱车检查）")
	public Response<List<Map<String,Object>>> acquireModel(@RequestParam(required=false) Integer seriesId) {
		logger.info("获取车型（爱车检查）==>start...");
		try {
			List<Map<String, Object>> result = carKnowledgesService.acquireModel(seriesId);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("获取车型（爱车检查）==>end...");
		}
	}
	
	
	
	/**
	 * 获取里程（爱车检查）
	 * @return
	 */
	@RequestMapping(value = "/acquireMileage", method = RequestMethod.GET)
	@ApiOperation(value = "获取里程（爱车检查）", notes = "获取里程（爱车检查）")
	public Response<List<Map<String,Object>>> acquireMileage() {
		logger.info("获取里程（爱车检查）==>start...");
		try {
			List<Map<String, Object>> result = carKnowledgesService.acquireMileage();
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("获取里程（爱车检查）==>end...");
		}
	}
	
	
	/**
	 * 获取结果（爱车检查）
	 * @return
	 */
	@RequestMapping(value = "/acquireResult", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	@ApiOperation(value = "获取结果（爱车检查）", notes = "获取结果（爱车检查）")
	public Response<List<TmExamineCarResult>> acquireResult(
			@RequestParam(required=false) Integer modelId,
			@RequestParam(required=false) String buyDate,
			@RequestParam(required=false) Integer travelMileage) {
		logger.info("获取结果（爱车检查）==>start...");
		logger.info("获取结果（爱车检查）modelId："+modelId);
		logger.info("获取结果（爱车检查）buyDate："+buyDate);
		logger.info("获取结果（爱车检查）travelMileage："+travelMileage);
		try {
			List<TmExamineCarResult> result = carKnowledgesService.acquireResult(modelId,buyDate,travelMileage);
			return new Response<>(ResultMsgConstants.RESULT_CODE_SUCCESS, result, "");
		} catch (Exception e) {
			logger.error("查询状态发生异常", e);
			return new Response<>(ResultMsgConstants.RESULT_CODE_ERROR, e.getMessage());
		} finally {
			logger.info("获取结果（爱车检查）==>end...");
		}
	}
}
